<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-select v-model="dataForm.classId"  placeholder="请选择班级">
        <el-option
          v-for="item in classOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="dataForm.startTime"
          type="date"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd"
          placeholder="选择开始日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="dataForm.endTime"
          type="date"
          format="yyyy 年 MM 月 dd 日"
          value-format="yyyy-MM-dd"
          placeholder="选择结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button @click="reset()">重置</el-button>
        <!-- <el-button v-if="isAuth(':edulesson:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth(':edulesson:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        type="index"
        header-align="center"
        align="center"
        width="80"
        label="序号">
      </el-table-column>
      <el-table-column
        prop="className"
        header-align="center"
        align="center"
        width="240"
        label="班级名称">
      </el-table-column>
      <el-table-column
        prop="totalNum"
        header-align="center"
        align="center"
        width="80"
        label="总人数">
      </el-table-column>

      <el-table-column
        prop="restCount"
        header-align="center"
        align="center"
        width="180"
        label="剩余报名人数">
      </el-table-column>
      <el-table-column
        prop="payCount"
        header-align="center"
        align="center"
        width="180"
        label="已报名人数">
      </el-table-column>
      <el-table-column
        prop="totalMoney"
        header-align="center"
        align="center"
        width="180"
        label="理论总收入(元)">
      </el-table-column>
      <el-table-column
        prop="payMoney"
        header-align="center"
        align="center"
        width="180"
        label="理论收入(元)">
      </el-table-column>
       <el-table-column
        prop="realPayMoney"
        header-align="center"
        align="center"
        width="180"
        label="实际收入(元)">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        dataForm: {
          classId: '',
          startTime: '',
          endTime: '',
        },
        dataList: [],
        classOptions: [],
        classId: '',
        startTime: '',
        endTime: '',
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,

      }
    },
    activated () {
      this.getDataList();
      this.getClassList();
    },
    methods: {
       // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      reset() {
        this.dataForm = {
          classId: '',
          startTime: '',
          endTime: '',
        }
        this.getDataList();
      },
      selectionChangeHandle() {

        },
      // 统计分析
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/sys/stat/class'),
          method: 'post',
          data: this.$http.adornData({
            'classId': this.dataForm.classId,
            'startTime': this.dataForm.startTime,
            'endTime': this.dataForm.endTime,
            'page': this.pageIndex,
            'limit': this.pageSize
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
          }
          this.dataListLoading = false
        })
      },
      getClassList() {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/sys/educlass/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': 1,
            'limit': 100,
            'isDeleted':0
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            let dataList = data.page.list
            let classOptions = [];
            dataList.forEach((item) => {
              let obj = {};
              obj.value = item.id;
              obj.label = item.name;
              classOptions.push(obj);

            })
            this.classOptions = classOptions;
          }
          this.dataListLoading = false
        })
      }
    }
  }
</script>
